package com.sang.servlet;

import com.sang.pojo.User;
import com.sang.util.Sendmail;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//脚手架

public class RegisterServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //接收用户请求，封装成对象
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String email = request.getParameter("email");

        User user = new User(username, password, email);

        //用户注册成功之后，给用户发送一封邮件
        //我们使用线程来专门发送邮件，防止出现耗时，和网站注册人数过多的情况：
        Sendmail send = new Sendmail(user);
        //启动线程，线程启动之后就会执行run方法来发送邮件
        send.start();

        //注册用户
        request.setAttribute("message","注册成功，我们已经发了一封带了注册信息的电子邮件，清查收！如网络不稳定，可能过会才能收到！！！");
        request.getRequestDispatcher("info.jsp").forward(request,response);

    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {

    }
}
